﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nvigorate.Relational.Mapping;
using Nvigorate.Relational.Mapping.Index;
using Nvigorate.TestObjects;

namespace Nvigorate.Test.Relational.Binding
{
    [TestClass]
    public class BindingMapLoaderFactoryTests
    {
        #region GetBindingMapLoaderTests

        [TestMethod]
        public void GetBindingMapLoader_ProvidingBindingElementAndNoXmlPath_ReturnsTypeBindingMapLoader()
        {
            // Act
            var factory = new BindingMapLoaderFactory();
            var actual = factory.GetBindingMapLoader(new MapElement {Type = typeof (Employee).FullName},
                                                     typeof (BindingMap));

            // Assert
            Assert.IsInstanceOfType(actual, typeof (TypeBindingMapLoader));
        }

        [TestMethod]
        public void GetBindingMapLoader_ProvidingBindingElementWithXmlPath_ReturnsXmlBindingMapLoader()
        {
            // Act
            var factory = new BindingMapLoaderFactory();
            var actual = factory.GetBindingMapLoader(new MapElement
                                                         {
                                                             Type = typeof (Employee).FullName,
                                                             XmlPath = "C:\\Test"
                                                         },
                                                     typeof (BindingMap));

            // Assert
            Assert.IsInstanceOfType(actual, typeof (XmlBindingMapLoader));
        }

        [TestMethod]
        public void GetBindingMapLoader_ProvidingMappedType_ReturnsTypeBindingMapLoader()
        {
            // Act
            var factory = new BindingMapLoaderFactory();
            var actual = factory.GetBindingMapLoader(typeof(Employee));

            // Assert
            Assert.IsInstanceOfType(actual, typeof(TypeBindingMapLoader));

        }

        [TestMethod]
        public void GetBindingMapLoader_ProvidingPath_ReturnsXmlBindingMapLoader()
        {
            // Act
            var factory = new BindingMapLoaderFactory();
            var actual = factory.GetBindingMapLoader("C:\\Test", typeof(BindingMap));

            // Assert
            Assert.IsInstanceOfType(actual, typeof(XmlBindingMapLoader));

        }
        #endregion
    }
}